package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * @ClassName AlertDemo
 * @Description
 * @Author wangss
 * @date 2020.06.13 18:19
 * @Version 1.0
 */
public class AlertDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #fff2f2");

        Button button = new Button("弹框");

        AnchorPane.setTopAnchor(button, 20d);
        AnchorPane.setLeftAnchor(button, 20d);
        anchorPane.getChildren().addAll(button);
        Scene scene = new Scene(anchorPane);
        primaryStage.setScene(scene);
        primaryStage.setWidth(800d);
        primaryStage.setHeight(800d);
        primaryStage.setTitle("Dialog");
        primaryStage.setResizable(false);
        primaryStage.show();

        button.setOnAction(event -> {
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION);

            Button okButton = (Button) alert.getDialogPane().lookupButton(ButtonType.OK);
            okButton.setOnAction(event1 -> {
                System.out.println("ok");
            });

            alert.show();
        });
    }
}
